﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CH.Study.ConsoleApp.ExpressionTree
{
    public class QueryPageList<T>
    {
        public int TotalRecord { get; set; }
        public int TotalPageCount { get; set; }
        public int PageIndex { get; set; }
        public int PageSize { get; set; }
        public List<T> List { get; set; }
        public QueryPageList(QueryQueryable<T> collection)
        {
            this.List = new List<T>();
            using (IEnumerator<T> enumerator = collection.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    this.List.Add(enumerator.Current);
                }
            }
            if (this.List.Count > 0)
            {
                PageEntity pe = collection.GetPageEntity();
                this.TotalRecord = pe.TotalRecord;
                this.PageIndex = pe.Index;
                this.PageSize = pe.Size;
                if (this.TotalRecord != 0)
                {
                    this.TotalPageCount = (int)(this.TotalRecord / this.PageSize);
                }
                else
                {
                    this.TotalPageCount = 0;
                }
            }

        }


    }
}
